package cn.bone.cloud.compute.feign.web;

import cn.bone.cloud.compute.feign.service.ComputeClient;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created by Administrator on 2017/11/2.
 */
@RestController
public class ComputeController {

    @Resource
    private ComputeClient computeClient;

    @RequestMapping("/add")
    public Integer add(){
        return computeClient.add(19,3);
    }

    @RequestMapping("/add2")
    public Integer add2(){
        return 33;
    }

    @RequestMapping("/user")
    public User getUser(){
        User user = new User();
        user.setBirthday(new Date());
        user.setId(10);
        user.setName("陈义龙");
        return user;
    }

    @RequestMapping("/test")
    public String test(){
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        String userAgent = request.getHeader("user-agent");
        System.out.println(userAgent);

        return "ok";
    }
}

@Data
class User{
    private Integer id;
    private String name;
    private Date birthday;
}
